<?php
session_start();
include('ConnectBdd.php');

$req="SELECT dom.Email_Equipe MailDom, Id_Match, dom.Libelle_Equipe eq1,Ext.Libelle_Equipe eq2,Score_Set1_Dom,Score_Set1_Ext,Score_Set2_Dom,Score_Set2_Ext,Score_Set3_Dom,Score_Set3_Ext,Score_Set4_Dom,Score_Set4_Ext,Score_Set5_Dom,Score_Set5_Ext,Date_Match,Libelle_Plage
FROM volley_equipe dom, volley_equipe ext, volley_match, volley_plage, volley_inscrire i
WHERE dom.Id_Equipe=Id_Equipe_dom
and ext.Id_Equipe=Id_Equipe_ext
and volley_plage.Id_Plage=volley_match.Id_Plage 
and i.Id_Equipe = dom.Id_Equipe
and i.Id_poule= (Select Id_poule
                From volley_inscrire i, volley_equipe e
                Where i.Id_Equipe = e.Id_Equipe AND 
                Email_Equipe='".$_SESSION['mail']."')";
?>
    <center>
        <br>
         <img src="./image/result_Class.png" height="150px" width="600px"/>
         <div class="tableau">
    <table cellspacing="1">
        <tr>
            <td>Equipe 1  </td>
            <td>Equipe 2</td>
            <td>Set 1</td>
            <td>Set 2</td>
            <td>Set 3</td>
            <td>Set 4</td>
            <td>Set 5</td>
            <td>Vainqueur</td>
            <td>date</td>
            <td>plage</td>
        </tr>
        
     <?php
     $result = $connexion->query($req);
            while ($row=$result->fetch(PDO::FETCH_ASSOC)){
                $NbSetEq1=0;
                $NbSetEq2=0;
                
                if($row['Score_Set1_Dom'] > $row['Score_Set1_Ext']){
                   $NbSetEq1+=1;
                }
               
                else if($row['Score_Set1_Dom'] < $row['Score_Set1_Ext']){
                     $NbSetEq2+=1;
                }
                
                 if($row['Score_Set2_Dom'] > $row['Score_Set2_Ext']){
                   $NbSetEq1+=1;
                }
                else  if($row['Score_Set2_Dom'] < $row['Score_Set2_Ext']){
                     $NbSetEq2+=1;
                }
                
                 if($row['Score_Set3_Dom'] > $row['Score_Set3_Ext']){
                   $NbSetEq1+=1;
                }
                else  if($row['Score_Set3_Dom'] < $row['Score_Set3_Ext']){
                     $NbSetEq2+=1;
                }
                
                 if($row['Score_Set4_Dom'] > $row['Score_Set4_Ext']){
                   $NbSetEq1+=1;
                }
                else  if($row['Score_Set4_Dom'] < $row['Score_Set4_Ext']){
                     $NbSetEq2+=1;
                }
                
                 if($row['Score_Set5_Dom'] > $row['Score_Set5_Ext']){
                   $NbSetEq1+=1;
                }
                else  if($row['Score_Set5_Dom'] < $row['Score_Set5_Ext']){
                     $NbSetEq2+=1;
                }
                
               if ($NbSetEq1 > $NbSetEq2){
                   $vainqueur= $row['eq1'];
               }
               else if($NbSetEq1 < $NbSetEq2) {
                   $vainqueur=$row['eq2'];
               }
               else {
                  $vainqueur="";
               }
           

                echo "<tr>";
                echo "<td>" . $row['eq1'] . "</td>";
                echo "<td>" . $row['eq2'] . "</td>";
                echo "<td>" . $row['Score_Set1_Dom'] ."/". $row['Score_Set1_Ext'] ."</td>";
                echo "<td>" . $row['Score_Set2_Dom'] ."/". $row['Score_Set2_Ext'] ."</td>";
                echo "<td>" . $row['Score_Set3_Dom'] ."/". $row['Score_Set3_Ext'] ."</td>";
                echo "<td>" . $row['Score_Set4_Dom'] ."/". $row['Score_Set4_Ext'] ."</td>";
                echo "<td>" . $row['Score_Set5_Dom'] ."/". $row['Score_Set5_Ext'] ."</td>";
                echo "<td>".$vainqueur."</td>";
                echo "<td>" . $row['Date_Match'] . "</td>";
                echo "<td>" . $row['Libelle_Plage'] . "</td>";
                ?>
        <?php if($row['MailDom']== $_SESSION['mail']){ ?>
        <td><input type='button' value='Gérer Match' class='bouton' onclick="refresh_div('centre', './page/Equipe_GererMatch.php?id_Match=<?php echo $row['Id_Match'];?>','GET');"/></td>
        
            <?php
        }
        else{
             echo "<td></td>";
        }
                echo "</tr>";
            }
     
     
     ?>
        
    </table>
    
    </div>
    </center>


<br>

    <style onload="refresh_div('bandeau', './page/choixMenu.php','POST');"/>
    

<?php
    //  }
  //    else include('connexion.php');
    ?>
